/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/maximum-product-subarray
   @Language: C++
   @Datetime: 19-11-21 10:39
   */

class Solution {
public:
	int maxProduct(vector<int>& nums) {
		if(nums.size()<1) return 0;
		int m=nums[0], n=nums[0], r=nums[0];
		for(int i=1; i<nums.size(); ++i){
			const int a=m*nums[i], b=n*nums[i];
			m=max(nums[i],max(a,b));
			n=min(nums[i],min(a,b));
			r=max(r,m);
		}
		return r;
	}
};
